package cn.cmdr.service.ServiceImpl;

import cn.cmdr.mapper.JournalMapper;
import cn.cmdr.mapper.MenuMapper;
import cn.cmdr.pojo.Journal;
import cn.cmdr.pojo.Menu;
import cn.cmdr.service.JournalService;
import cn.cmdr.vo.JournalVo;
import cn.cmdr.vo.PageVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service("journalService")
public class JournalServiceImpl extends ServiceImpl<JournalMapper, Journal> implements JournalService {
    @Resource
    private JournalMapper journalMapper;
    @Resource
    private MenuMapper menuMapper;
    @Override
    public PageVo getJournalList(Integer pageNo, Integer pageSize, JournalVo journalVo) {
        Page page = new Page();
        page.setSize(pageSize);
        page.setCurrent(pageNo);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(journalVo.getStaffId()!=null,"staff_id",journalVo.getStaffId())
                .eq(journalVo.getMenuId()!=null,"menu_id",journalVo.getMenuId())
                .gt(journalVo.getStime()!=null,"up_date",journalVo.getStime())
                .lt(journalVo.getEtime()!=null,"up_date",journalVo.getEtime())
                .orderByDesc("up_date");
        List list = journalMapper.getJournalList(page,queryWrapper);
        return new PageVo(list,page.getTotal());
    }

    @Override
    public void add(Journal journal) {
        journalMapper.insert(journal);
    }

    @Override
    public List<Menu> getMenuList() {
        return menuMapper.selectList(null);
    }
}
